package com.dhcc.sds.standard.controller;

import com.baomidou.mybatisplus.plugins.Page;
import com.dhcc.core.framework.base.controller.BaseController;
import com.dhcc.core.framework.base.warpper.EmptyWarpper;
import com.dhcc.core.framework.result.R;
import com.dhcc.core.framework.result.node.ZTreeNode;
import com.dhcc.core.framework.result.page.PageFactory;
import com.dhcc.core.modules.system.cache.config.ConfigCache;
import com.dhcc.sds.standard.entity.SdsStandDicsubEntity;
import com.dhcc.sds.standard.service.ISdsStandDicService;
import com.dhcc.sds.standard.service.ISdsStandDicsubService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.Map;

/**
 * 药品标准化维护
 *
 * @ClassName: SdsStandDrugController
 * @Description: TODO
 * @author zhangdc
 * @date 2021-03-25 10:09:53
 */
@Controller
@RequestMapping("${sys.backendPath}/sds/sdsstanddrug")
public class SdsStandDrugController extends BaseController {

    private String PREFIX = "/backend/sds/sdsstanddrug/";

    @Autowired
    private ISdsStandDicsubService sdsStandDicsubService;

    @Autowired
    private ISdsStandDicService sdsStandDicService;

    /**
     * 跳转到药品标准化维护页面
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "sdsstanddrug.html";
    }

    /**
     * 获取药品名称列表
     */
    @SuppressWarnings("unchecked")
    @RequestMapping(value = "/list")
    @ResponseBody
    public Object list(@RequestParam Map<String, Object> params) {
        Page<SdsStandDicsubEntity> page = new PageFactory<SdsStandDicsubEntity>().defaultPage();
        List<SdsStandDicsubEntity> result = this.sdsStandDicsubService.pageByDrug(page,params);
        page.setRecords((List<SdsStandDicsubEntity>) new EmptyWarpper(result).warp());
        return R.packForBT(page);
    }

    /**
     * 获取分类的tree列表
     */
    @RequestMapping(value = "/tree")
    @ResponseBody
    public List<ZTreeNode> categoryTree() {
        return sdsStandDicService.getCategoryTree();
    }
}
